<html>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- jQuery.js -->
<script src="<?=$mvc->parse('{base_url}')?>js/jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="<?=$mvc->parse('{base_url}')?>js/jquery-ui-1.8.15.custom.min.js" type="text/javascript"></script>
<script src="<?=$mvc->parse('{base_url}')?>js/jquery.cookie.js" type="text/javascript"></script>
<!-- jQuery.css -->
<link href="<?=$mvc->parse('{base_url}')?>css/smoothness/jquery-ui-1.8.15.custom.css" rel="stylesheet" type="text/css" media="all" />

<!-- main -->
<script src="<?=$this->data_url?>index_stor.js" type="text/javascript" ></script>
<link rel="stylesheet" type="text/css" media="all" href="<?=$this->data_url?>index_stor.css" />


<!-- TinyMCE editor -->
<script src="../assets/plugins/tinymce3201/jscripts/tiny_mce/tiny_mce.js" type="text/javascript"></script>

<!-- Class for selecting files -->
<script src="/myassets/js/myfileselector.js" type="text/javascript"></script>
<!-- Widget for displaying trees. -->
<script src="../myassets/js/TreeWidget.js" type="text/javascript"></script>

<script type="text/javascript" src="../myassets/libs/storage/ctree.js"></script>




<body style="width:100%; height:100%; margin:0; background:#fff">
<?
	// m0_.
	// include_once('class_storage.php');

	// global $stor;
	// $stor = new CStorage();
	// $stor->dataFolder = '/assets/files';
	/*
	$prelink = '?';
	
	$cmd = isset($_REQUEST['m0_cmd']) ? $_REQUEST['m0_cmd'] : '';
	if (!$cmd) $cmd = isset($_REQUEST['m_cmd']) ? $_REQUEST['m_cmd'] : '';

	$id = isset($_REQUEST['m0_id']) ? $_REQUEST['m0_id'] : '';
	$name = isset($_REQUEST['m0_name']) ? $_REQUEST['m0_name'] : '';
	if (!$name) $name = isset($_REQUEST['m_name']) ? $_REQUEST['m_name'] : '';

	$ffilter = isset($_REQUEST['m0_ffilter']) ? $_REQUEST['m0_ffilter'] : '';
	$page = (isset($_REQUEST['m0_page']) ? (int)$_REQUEST['m0_page'] : 1);

	$name = strtolower($name);
	
	//$stor->setName(mysql_escape_string($name));
	$table = new c_table_model($name);

	switch ($cmd)
	{
		case 'delstor':
			$stor->removeStorage();
			$cmd = '';
			break;

		//    .
		case 'edtstor2':
			$cnt = (int)$_REQUEST['m_stor_fcount'];
			$table->name = mysql_escape_string($_REQUEST['m_name']);
			$table->comment = mysql_escape_string($_REQUEST['m_desc']);
			$table->fields = array();

			for($i = 0; $i < $cnt; $i++)
			{
				$field = array();
				$field['name'] = $_REQUEST['m_stor_f'.$i.'N'];
				$field['type'] = $_REQUEST['m_stor_f'.$i.'T'];
				$field['len'] = $_REQUEST['m_stor_f'.$i.'L'];
				$field['comment'] = $_REQUEST['m_stor_f'.$i.'C'];

				$table->fields[$field['name']] = $field;//$_REQUEST['m0_stor_f'.$i.'N']] = $_REQUEST['m0_stor_f'.$i.'T'];
			}
			echo '<pre>';
			print_r($table);
			$table->save();
			//$stor->createStorage();
			$cmd = '';
			$view = new c_view_util();
			echo $view->render('system/mody_messages', $mvc->messages);

			$cmd = '';
			break;

			$cnt = (int)$_REQUEST['m0_stor_fcount'];
			$stor->description = mysql_escape_string($_REQUEST['m0_desc']);
			$stor->form_code = mysql_escape_string($_REQUEST['m0_form_code']);
			for($i = 0; $i < $cnt; $i++)
				$stor->fields[$_REQUEST['m0_stor_f'.$i.'N']] = $_REQUEST['m0_stor_f'.$i.'T'];
			//$stor->createStorage();
			$cmd = '';
			break;
			
		case 'setrow':
			$stor->getInfo();			
			$stor->data[0]['id'] = $_REQUEST['m0_stor_fid'];
			
			foreach($stor->fields as $k=>$v)
			{
				if (isset($_REQUEST['m0_stor_f'.$k]))
					$stor->data[0][$k] = $_REQUEST['m0_stor_f'.$k];
				else if (isset($_FILES['m0_stor_f'.$k]))
					$stor->data[0][$k] = 'm0_stor_f'.$k;
				else
					$stor->data[0][$k] = '';
			}				
			$stor->setData();
			$cmd = 'data';

			break;

		case 'delrow':
			$stor->deleteData('id='.$id);
			$cmd = 'data';
			break;
	}	
	
	*/
?>
		
<? if ($cmd == '') {?>
			<table width="100%" class="datatable">
				<tr>
					<th><?= $mvc->tr("name") ?></th>
					<th><?= $mvc->tr("description") ?></th>
					<th><a id="btn_add" href="<?=$this->base_url?>edit" title="Append storage">A</a></th>
				</tr>

				<?
					$list = $mvc->db->list_tables();

					foreach($list as $key => $row)
					{
						echo '<tr onmouseover="this.style.background=\'#eee\'" onmouseout="this.style.background=\'#fff\'">';
						echo '	<td>'.$row['name'].'</td>';
						echo '	<td>'.$row['comment'].'</td>'. //echo '	<td>'.$row['description'].'</td>'.

							'	<td width="51px">'.
							'		<a href="'.$mvc->parse('{base_url}table/data').'?name='.$row['name'].'" title="Edit data" class="btn_data">D</a>'.							
							'		<a href="'.$mvc->parse('{base_url}table/edit').'?name='.$row['name'].'" title="Edit structure" class="btn_edit">E</a>'.
							'		<a onclick="return confirm(\'Storage will be completely removed. Are you sure?\')" '.
								'href="'.$mvc->parse('{base_url}table/delete').'?name='.$row['name'].'" title="Remove storage" class="btn_del">X</a>'.
							'	</td>'.
							'</tr>';

						echo $html;
					}
				?>
			</table>

<? } elseif($cmd == 'edtstor') {  //   . ?>
	<? include('views/index_stor.edit.php'); ?>

<? }elseif($cmd == 'data') {?>

	<? include('views/index_stor.data.php'); ?>

<? } elseif($cmd == 'data_edt') {?>
	<? include('views/index_stor.data_edt.php'); ?>
	
<? } elseif($cmd == 'search') { ?>
	<? include('views/index_stor.search.php'); ?>

<? } ?>

<div id="selfile" style="width:300px; background:#CCCCCC; display:none; text-align:left; padding:4px">
	File selector
</div>
	
<script>

jQuery(function()
{
		jQuery('#btn_add').button({icons:{primary:'ui-icon-circle-plus'}, text:false}).width('16px').height('16px');
		jQuery('.btn_edit').button({icons:{primary:'ui-icon-pencil'}, text:false}).width('16px').height('16px');
		jQuery('.btn_del').button({icons:{primary:'ui-icon-trash'}, text:false}).width('16px').height('16px');
		jQuery('.btn_data').button({icons:{primary:'ui-icon-contact'}, text:false}).width('16px').height('16px');
		jQuery('#btn_set').button({icons:{primary:'ui-icon-circle-check'}, text:false}).width('16px').height('16px');
		
		jQuery('a.ui-button._ajax').click(function(event) { event.preventDefault(); loadActTab(this.href); });
});

function loadActTab(url, data)
{
	jQuery('#tabs').find('.ui-tabs-panel').not('.ui-tabs-hide').html('loading...');
	jQuery('#tabs').find('.ui-tabs-panel').not('.ui-tabs-hide').load(url, data);
}

</script>

</body>
</html>